#include	"WindowExplorer.hpp"

WindowExplorer::WindowExplorer(unsigned int heigthWinCode, unsigned int widthWinCode)
{
  this->_height = heigthWinCode;
  this->_width = COLS - widthWinCode;
  this->_win = newwin(this->_height, this->_width, 0, widthWinCode);
  box(this->_win, 0, 0);
  wrefresh(this->_win);
  
  //open / read File
  this->_fileTree = new ContentFile("./norme/file");

  //new ScrollText for displaying
  this->_scrollText = new ScrollText(this->_fileTree->getList(), this->_height, this->_width, this->_win);
}

void	WindowExplorer::checkEvent(int event)
{
  if (event == KEY_DOWN)
    this->_scrollText->cursorDown();
  else if (event == KEY_UP)
    this->_scrollText->cursorUp();
  else if (event == KEY_ENTER)
    {
      
    }  
}

std::string	WindowExplorer::getLineOnCursor()
{
  size_t	pos;

  pos = this->_scrollText->getLineOnCursor().find(";");
  return (this->_scrollText->getLineOnCursor().substr(0, pos));
}

WindowExplorer::~WindowExplorer()
{
  
}

void	WindowExplorer::update(bool focus)
{
  if (focus)
    enableColorPair1(this->_win);
  box(this->_win, 0, 0);
  if (focus)
    disableColorPair1(this->_win);
  this->_scrollText->update();
  wrefresh(this->_win);
}
